package day11;

import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DDLTest4 {
    public static void main(String[] args) throws SQLException {

        /**
         * 贾链欲其事
         * 贾: 加载驱动
         * 链: 获得链接
         * 欲: 获得Statement语句对象
         * 执: 执行sql
         * 事: 释放
         */

        Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/" +
                "hrm?useSSL=false&useUnicode=true&characterEncoding=utf-8", "root", "123456");
        System.out.println("conn:" + conn);

        ResultSet rs = null;

        //获得语句对象
        Statement st = conn.createStatement();

        String sql = "select * from employees";
        rs = st.executeQuery(sql);


        while (rs.next()) {
            String employee_id = rs.getString(1);
            String first_name = rs.getString(2);
            String last_name = rs.getString(3);
            String email = rs.getString(4);
            String phone_number = rs.getString(5);
            String job_id = rs.getString(6);
            String salary = rs.getString(7);
            String commission_pct = rs.getString(8);
            String manager_id = rs.getString(9);
            String department_id = rs.getString(10);
            String hiredate = rs.getString(11);
            String sex = rs.getString(12);
            String age = rs.getString(13);
            System.out.println(employee_id + "\t" + "\t" + first_name + "\t" + "\t" + last_name + "\t" + "\t" +
                    email + "\t" + "\t" + phone_number + "\t" + "\t" + job_id + "\t" + "\t" + salary + "\t" + "\t" + commission_pct
                    + "\t" + "\t" + manager_id + "\t" + "\t" + department_id + "\t" + "\t" + hiredate + "\t" + "\t" + sex + "\t" + "\t" + age);
        }

        System.out.println("创建成功");

        rs.close();
        st.close();
        conn.close();
    }
}
